package com.voicechat.firstmet.activity;

import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.View;
import android.widget.LinearLayout;

import com.voicechat.firstmet.R;
import com.voicechat.firstmet.base.BaseActivity;
import com.voicechat.firstmet.fragment.LookMeFragment;
import com.voicechat.firstmet.utils.StatusBarUtils;
import com.voicechat.firstmet.view.LazyViewPager;
import com.voicechat.firstmet.view.SimpleViewPagerIndicatorLook;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ProjectName: FirstMet
 * @Package: com.voicechat.firstmet.activity_imessage
 * @ClassName: LookMeActivity
 * @Description: 谁看过我  和我看过谁页面
 * @Author: ljp
 * @CreateDate: 2018/10/11 16:28
 * @Version: 1.0
 */
public class LookMeActivity extends BaseActivity {

    @BindView(R.id.linear_back)
    LinearLayout linearBack;
    @BindView(R.id.indicator_look_me)
    SimpleViewPagerIndicatorLook indicatorLookMe;
    @BindView(R.id.lookme_list)
    LazyViewPager lookmeList;
    private String[] mTitles;
    private ArrayList<Fragment> fragments;
    private LookMeActivity.MyAdapter mAdapter;
    private String vType;

    @Override
    protected int setStatusBarColor() {
        return 0;
    }

    @Override
    protected boolean isSettingStatusBarText() {
        return false;
    }
    @Override
    protected int loadLayout() {
        return R.layout.activity_look_me;
    }
    @Override
    protected void initLayout(Bundle savedInstanceState) {
        ButterKnife.bind(this);
        StatusBarUtils.Full(this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
        initView();
    }
    @OnClick(R.id.linear_back)
    public void onClick() {
        finish();
    }
    /**
     * 数据实例化
     */
    private void initView() {
        vType = getIntent().getStringExtra("vType");
        mTitles = getResources().getStringArray(R.array.lookme_list);
        initIndicator();
        bindEvent();
        initViewPager();
    }
    /**
    * @method
    * @description viewpager与fragment绑定
    * @date: 2018/10/11 16:40
    * @author: ljp
    * @return
    */
    private void initViewPager() {
        fragments = new ArrayList<>();
        fragments.add(LookMeFragment.newInstance("LOOKME",vType));//谁看过我
        fragments.add(LookMeFragment.newInstance("MELOOK",vType));//我看过谁
        mAdapter = new LookMeActivity.MyAdapter(getSupportFragmentManager());
        lookmeList.setAdapter(mAdapter);
    }
    /**
    * @method
    * @description 标题滑动监听
    * @date: 2018/10/11 16:40
    * @author: ljp
    * @return
    */
    private void bindEvent() {
        indicatorLookMe.setOnPageChangeListener(new SimpleViewPagerIndicatorLook.OnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                indicatorLookMe.setCurrentItem(position);
            }

        });
    }
    /**
    * @method
    * @description fragment切换标题数据
    * @date: 2018/10/11 16:42
    * @author: ljp
    * @return
    */
    private void initIndicator() {
        if (null == mTitles || mTitles.length == 0) {
            indicatorLookMe.setVisibility(View.GONE);
        } else {
            indicatorLookMe.setTitles(mTitles);
            indicatorLookMe
                    .setViewPager(lookmeList);
            lookmeList.setCurrentItem(0);
        }
    }
    private class MyAdapter extends FragmentStatePagerAdapter {
        public MyAdapter(FragmentManager fm) {
            super(fm);
            // TODO Auto-generated constructor stub
        }
        @Override
        public Fragment getItem(int arg0) {
            // TODO Auto-generated method stub
            return fragments.get(arg0);
        }
        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return fragments.size();
        }

    }
}
